package com.lyh.hkcloud.module.m1300023.service;

import android.app.Activity;
import android.util.Log;
import com.lyh.hkcloud.constants.HttpUrlComstants;
import com.lyh.hkcloud.module.common.ModuleService;
import com.lyh.hkcloud.util.base.StringUtils;
import com.lyh.hkcloud.util.base.ToastUtils;
import com.lyh.hkcloud.util.http.Request;
import com.lyh.hkcloud.util.http.listener.json.JsonFailuredListener;
import com.lyh.hkcloud.util.http.listener.json.JsonSuccessListener;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author: zhongfan
 * @program: hkCloud
 * @description:
 * @company—date: 利元数据 2022-02-11 16:59
 **/
public class Service extends ModuleService {


    public Service(Activity activity) {
        super(activity);
    }

    /**
     * 根据资产编号查询资产信息
     * @param jsonObject
     * @param successListener
     * @param failuredListener
     * @return void
     * @author: zhongfan
     * @Date 2022/2/14 14:18
    **/
    public void post(JSONObject jsonObject,String interfaceAddress, final JsonSuccessListener successListener, final JsonFailuredListener failuredListener) {
        Request.post(activity, HttpUrlComstants.DOMAIN_NAME_URL + interfaceAddress, jsonObject, new JsonSuccessListener() {
            @Override
            public void onRespone(String msg, JSONObject response) {
                try {
                    if (StringUtils.responseResults(response)) {
                        successListener.onRespone(msg, response);
                    } else {
                        ToastUtils.makeText(activity, response.optString("message"), ToastUtils.LENGTH_SHORT).show();
                        failuredListener.onRespone(response.optString("message"), null);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new JsonFailuredListener() {
            @Override
            public void onRespone(String msg, JSONObject response) {
                Log.e("error",response.optString("message"));
                ToastUtils.makeText(activity, response.optString("message"), ToastUtils.LENGTH_SHORT).show();
                failuredListener.onRespone(msg, response);
            }
        });
    }

}
